#!/bin/bash

# 默认参数值
op=""
dev=""
can_up(){    
    for link in "$@"; do
        echo "starting $link"
        sudo ip link set $link down 
        echo "set qlan"
        sudo ip link set $link qlen 100
        echo "set bitrate"
        sudo ip link set $link type can bitrate 1000000
        sudo ip link set $link up 
    done
}
can_down(){
    for link in "$@"; do
        echo "stopping $link"
        sudo ip link set $link down
    done
}

# 解析参数
while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        up|down)
            op="$key"
            shift # 切换到下一个参数
            ;;
        *)
            dev+="$1" # 将can0和can1合并为一个参数
            shift # 切换到下一个参数
            ;;
    esac
done

# 调用内部函数，传递合并的can参数
# internal_function "$combined_can"
if [ "$op" == "up" ]; then
    can_up "$dev"
elif [ "$op" == "down" ]; then
    can_down "$dev"
fi
